#define _CRT_SECURE_NO_WARNINGS

1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4 #include<unistd.h>
5 #include<sys/wait.h>
6 #include<sys/types.h>
7 #define SIZE 64
8 char usercommand[SIZE];
9 char* pch[SIZE];
10 int main()
11 {
	12   printf("[%s@%s %s]", getenv("LOGNAME"), getenv("HOSTNAME"), getenv("HOME"));
	13   fgets(usercommand, sizeof usercommand, stdin);
	14   //printf("%s", usercommand);  
		15   int i = 0;
	16   pch[i] = strtok(usercommand, " ");
	17   while (pch[i])
		18   {
		19     //printf("%s", pch);  
			20     pch[++i] = strtok(NULL, " ");
		21   }
	22   pid_t id = fork();
	23   // process replace  
		24   if (id == 0) // child  
		25   {
		26     execvp(pch[0], pch);
		27     exit(1);
		28   }
	29   else // father
		30   {
		31     waitpid(-1, NULL, 0);
		32   }
	33   return 0;
	34 }